#!/usr/bin/python
# -*- coding: UTF-8 -*-
from tkinter import Menu, Button

from base.BaseMainWindow import BaseMainWindow
from sdautolayout.sdautolayout import sdautolayout
from ui.account.AccountWindow import AccountWindow
from ui.channel.ChannelWindow import ChannelWindow
from utils.BrowserUtils import BrowserUtils


class Main(BaseMainWindow):
    def __init__(self):
        super(Main, self).__init__(width=500,height=50,title='推广神器')
        self.init_ui()
        self.init_menu()

    def init_ui(self):
        self.button_start_chrome = Button(self,text='启动浏览器',command=self.startupChrome)
        self.button_start_chrome.place(x=5,y=5)
        sdautolayout.forWidget(self.button_start_chrome).widthIs(self.getWidth()-10).heightIs(self.getHeight()-10)

    def init_menu(self):
        # 在大窗口下定义一个菜单实例
        menubar = Menu(self)
        # 给菜单实例增加菜单项
        table = {'推广渠道': self.channel,  '账号': self.account, '推广内容': self.account, '关于': self.account}
        map = dict([(v, k) for v, k in table.items()])
        for key in map.keys():
            menubar.add_command(label=key,command=map[key])
        # 菜单实例应用到大窗口中
        self['menu'] = menubar


    def startupChrome(self):
        BrowserUtils.instance().load("http://www.baidu.com")


    def channel(self):
        ChannelWindow(self)

    def account(self):
        AccountWindow(self)


main = Main()
main.show()